/**
 * @author Juko
 * @version 0.1
 */

package ganga.custodian.dashboard;

import ganga.custodian.CustodianApplication;
import ganga.custodian.R;

import java.util.Vector;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.androidplot.xy.XYPlot;

/**
 * Визуализатор монитора
 * 
 * @author Juko
 * @version 0.2
 * @updated 14-июл-2011 17:49:48
 */
public class MonitorScreenActivity extends Activity {

	private TextView bpmText;
	private TextView realKIG;
	MonitorScreenPlotData plotData = new MonitorScreenPlotData(
			new Vector<Double>() ,new Vector<Double>());

	@Override
	protected void onResume() {
		super.onResume();
		setCurrentTheme();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.monitorscreenactivity);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setCurrentTheme();
		bpmText = (TextView) findViewById(R.id.bpmText);
		plotData.kigPlot = (XYPlot) findViewById(R.id.rigPlot);
		plotData.bpmPlot = (XYPlot) findViewById(R.id.bpmPlot);
		realKIG = (TextView) findViewById(R.id.realKIG);
		plotData.buildXYPlot(this, plotData.kigPlot);
		plotData.buildXYPlot(this, plotData.bpmPlot);

		registerReceiver(new BroadcastReceiver() {
			@Override
			public void onReceive(Context arg0, Intent receivedIntent) {
				Integer newInterval = receivedIntent.getIntExtra("RRInterval",
						900);
				Integer newHeartRate = receivedIntent.getIntExtra("CurrHeartRate",
						900);
				double interval = newInterval.doubleValue();
				double heartRate = newHeartRate.doubleValue();
				plotData.setNewInterval(ganga.custodian.dashboard.MonitorScreenActivity.this, interval);
				plotData.setNewHeartRate(ganga.custodian.dashboard.MonitorScreenActivity.this, heartRate );
				bpmText.setText(Double.toString(heartRate));
				realKIG.setText(Double.toString(interval));

			}
		}, new IntentFilter("Redraw"));
	}

	private void setCurrentTheme() {
		LinearLayout thisLayout = (LinearLayout) findViewById(R.id.realTimeMonitorLayout);
		thisLayout.setBackgroundColor(CustodianApplication.getInstance().selectTheme.backGround);
		TextView firstLabel = (TextView) findViewById(R.id.textView1);
		TextView secondLabel = (TextView) findViewById(R.id.textView3);
		TextView TirdLabel = (TextView) findViewById(R.id.bpmText);
		TextView FourLabel = (TextView) findViewById(R.id.realKIG);
		firstLabel.setTextColor(CustodianApplication.getInstance().selectTheme.firstColour);
		secondLabel.setTextColor(CustodianApplication.getInstance().selectTheme.firstColour);
		TirdLabel.setTextColor(CustodianApplication.getInstance().selectTheme.firstColour);
		FourLabel.setTextColor(CustodianApplication.getInstance().selectTheme.firstColour);

	}

}